@extends('admin.adminbase')
@section('content')


	<section class="hbox stretch">
		@include("admin.public.left")

		<aside>
			<section class="vbox">
				<header class="header bg-white b-b clearfix">
					<form class="talbe-search" method="get" action="">
						<div class="row m-t-sm">
							<div class="col-sm-12 m-b-xs">
								<div class="btn-group" role="group">
									<strong style="line-height:30px;">添加Banner</strong>
								</div>

								<div class="btn-group pull-right">
									<a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
										<i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
									</a>
								</div>

							</div>
						</div>
					</form>
				</header>
				<section class="scrollable  wrapper w-f">
					<section class="panel panel-default ">
						<div class="row m-l-none m-r-none bg-light lter">
							<div class="container" style="padding: 20px 0px">
								<form id="formclass" class="form-horizontal" style="padding-top: 15px;">
									<div class="form-group">
										<label class="col-sm-3 control-label">轮播图 <span class="red">*</span></label>
										<div class="col-sm-4 ">
											<img src="" id="file_img" style="display: none;margin-bottom: 10px;" width="80" height="80">
											<input type="file" class="form-control" id="input_file" data-src="{{ url('upload/img') }}" placeholder="请输入标题">
											<input type="hidden" id="input_hidden"  name="pic_url">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-3 control-label">展示位置 <span class="red">*</span></label>
										<div class="col-sm-4 ">
											<select  class="form-control" name="position">
												<option value="0">请选择</option>
												<?php
												$positionList = \App\Http\Util\BannerPosition::getList();
												?>
												@foreach($positionList as $position)
													<option value="{{ $position['value'] }}">{{ $position['label'] }}</option>
												@endforeach
											</select>
										</div>
									</div>

									<input type="hidden" name="site" value="{{ \App\Http\Util\Site::WEB }}">

									<div class="form-group">
										<label class="col-sm-3 control-label">跳转地址<span class="red">*</span></label>
										<div class="col-sm-4 ">
											<input type="text" class="form-control" name="link_url" pattern="[a-zA-z]+://[^\s]*"
												   placeholder="请输入跳转地址">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label">备注</label>
										<div class="col-sm-4 ">
											<textarea name="remark" rows="5" cols="50"></textarea>
										</div>
									</div>

									<div class="form-group">
										<label class="control-label col-sm-3">状态<span class="red">*</span></label>
										<div class="col-sm-4" style="margin-top: 5px">
											<input type="radio" id="status1" name="status" checked value="1">
											<label for="status1">启用</label>
											<input type="radio" id="status0" name="status" value="2">
											<label for="status0">禁用</label>
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label"></label>
										<div class="col-sm-2 ">
											<button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
											<input type="checkbox" id="back">
											<label for="back">返回列表</label>
										</div>
									</div>
								</form>
							</div>
						</div>
					</section>
				</section>
			</section>
		</aside>
	</section>
@endsection
@section('addscript')
	<script>
		$(function(){
			$("#input_file").change(function(){
				changePic("input_file","file_img","input_hidden")
			});

			//提交表单
			var checkSubmitFlg = false;
			$('#formclass').on('submit',function(){
				if(checkSubmitFlg ==true){
					return false;
				}
				checkSubmitFlg = true;
				var data = $(this).serialize();
				var checked = $('#back').is(':checked');
				//验证表单
				var link_url = $('[name=link_url]').val();
				var remark = $('[name=remark]').val();

				var position = $('select[name=position]').val();
				if(position == 0){
					layer.alert('请选择轮播图位置');
					checkSubmitFlg = false;
					return false;
				}
				if(!link_url){
					layer.alert('请填写跳转地址');
					checkSubmitFlg = false;
					return false;
				}
				$.post("{{ url('admin/banner/create') }}",data,function(data){
					layer.msg(data.msg);
					if(data.success){
						if(checked){
							setTimeout(function(){
								location.href = "{{ url('admin/banner') }}";
							},1500);
						} else {
							location.reload();
						}
					}
				});
				return false;
			});

		});
	</script>
@endsection
